package org.springframework.samples.travel.application.impl;

import org.springframework.samples.travel.application.CountingService;

public final class CountingServiceImpl implements CountingService {

    private static volatile CountingServiceImpl _Instance = new CountingServiceImpl();

    private int _TotalConnections = 0;
    private int _SuccessfulConnections = 0;

    private CountingServiceImpl() {
    }

    @Override
    public int getTotalConnections() {
	return _TotalConnections;
    }

    @Override
    public int getTotalFailedConnections() {
	return _TotalConnections - _SuccessfulConnections;
    }

    @Override
    public int getTotalSuccessfulConnections() {
	return _SuccessfulConnections;
    }

    @Override
    public synchronized void incrementTotalConnections() {
	_TotalConnections++;
    }

    @Override
    public synchronized void incrementTotalSuccessfulConnections() {
	_SuccessfulConnections++;
    }

    public static CountingService instance() {
	return _Instance;
    }
}
